package com.zaicheng.cloud.loadbanlancer.server.impl;
/**
 @author zaicheng
 @version 1.0
 @date 2022-04-19
 @email zzc15847256473@163.com
 */

import com.alibaba.nacos.api.naming.pojo.Instance;
import com.zaicheng.cloud.loadbanlancer.server.Server;

import java.util.Map;

public class NacosServer extends Server {

        private final Instance instance;

        private final Map<String,String> metadata;

        private  final  MetaInfo metaInfo;

        public  NacosServer(final  Instance  instance){
            super(instance.getIp(),instance.getPort());
            this.instance = instance;
            this.metaInfo = new MetaInfo() {
                @Override
                public String getAppName() {
                    return instance.getServiceName();
                }

                @Override
                public String getServerGroup() {
                    return null;
                }

                @Override
                public String getServiceIdForDiscovery() {
                    return null;
                }

                @Override
                public String getInstanceId() {
                    return instance.getInstanceId();
                }
            };
            this.metadata = instance.getMetadata();
        }

    public MetaInfo getMetaInfo() {
        return this.metaInfo;
    }

    public  Instance getInstance(){
        return  this.instance;
    }

    public Map<String,String>  getMetadata(){
        return this.metadata;
    }

}
